//找出只出现一次的元素
function single(nums: number[]) {
    let num = -1
    for (let i = 0; i < nums.length; i++) {
        if (nums.indexOf(nums[i]) == nums.lastIndexOf(nums[i])) {
            num = nums[i]
        }
    }
    return num
}
console.log(single([1, 2, 1, 2, 4, 2]));
//多维转一维
function flat<T>(arr: Array<T>, k = 1): Array<T> {
    let narr: Array<T> = []
    arr.forEach((item: T) => {
        if (Array.isArray(item) && k >= 1) {
            narr = narr.concat(flat(item, k - 1))
        } else {
            narr = narr.concat(item)
        }
    })
    return narr
}
console.log(flat([1, [1, 2, 3, [1, 2, 3, 4, 5, 6]]]));

//一致字符串
let allowd = 'ab';
let words = ['ab', 'ac', 'abab']
function fn1(words: string[], allowd: string) {
    let obj = allowd.split('')
    let count: number = 0
    words.forEach((item, index) => {
        let items = item.split('')
        let c = 0
        items.forEach((v, i) => {
            if (v === obj[0] || v === obj[1]) {
                c++
            }
        })
        if (item.length === c) {
            count++
        }
    })
    return count
}
console.log((fn1(words, allowd)));

